package model

import (
	"gorm.io/gorm"
	"smart-health-platforms/config"
	"time"
)

type AchievementRule struct {
	Id        uint           `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	Name      string         `gorm:"column:name;type:varchar(255);comment:规则名称;not null;" json:"name"`                       // 规则名称
	RuleDesc  string         `gorm:"column:rule_desc;type:varchar(255);comment:规则描述;not null;" json:"rule_desc"`             // 规则描述
	Condition string         `gorm:"column:condition;type:varchar(255);comment:触发条件;not null;" json:"condition"`             // 触发条件
	Reward    string         `gorm:"column:reward;type:varchar(255);comment:奖励;not null;" json:"reward"`                     // 奖励
	Status    uint           `gorm:"column:status;type:int UNSIGNED;comment:状态：1：启用 2：禁用;not null;default:0;" json:"status"` // 状态：1：启用 2：禁用
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (ar *AchievementRule) TableName() string {
	return "achievement_rule"
}

// 成就规则添加
func (ar *AchievementRule) CreateAchievementRule() error {
	return config.DB.Create(&ar).Error
}
